package model;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

class PasswordHasher {

	private static MessageDigest md;

	PasswordHasher() {
		if (md == null) {
			try {
				md = MessageDigest.getInstance("SHA-512");
			} catch (NoSuchAlgorithmException e) {
				e.printStackTrace();
			}
		}
	}

	String toHash(String string) {
		try {
			return new BigInteger(1, md.digest(string.getBytes("UTF-8"))).toString(16);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			throw new RuntimeException(e.getMessage());
		}
	}
}
